use crate::dao;
use crate::models::models::command::Command;
use crate::runtime::response::MagicBoxResponse;
use crate::runtime::result::MagicBoxResult;

#[tauri::command(rename_all = "snake_case")]
pub(crate) async fn invoke_get_command_history() -> MagicBoxResult<MagicBoxResponse<Vec<Command>>> {
    let mut cnt = 100usize;

    let setting_value = dao::setting::get_setting_value("system.message.length");
    if setting_value.is_some() {
        let setting_value = setting_value.unwrap().parse::<usize>();
        if setting_value.is_ok() {
            cnt = setting_value.unwrap();
        }
    }

    let history = dao::command::get_command_history(cnt)?;

    Ok(MagicBoxResponse::new_success(history))
}